package com.wontube.smr.bo.sites.vevo;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.wontube.client.extension.utils.ArrayUtils;
import com.wontube.client.extension.utils.StringUtils;
import com.wontube.smr.bo.constants.StandarMusicGenres;

/**
 * 
 * @author tanggf(2012-8-7)
 *
 */
public final class VevoMusicGenres {
	private VevoMusicGenres(){}
	
	//网站使用的music genre映射到标准genre
	//private static final Map<String, String> siteStandarMap = new LinkedHashMap<String, String>();	
		
	private static final Map<String, String> map = new HashMap<String, String>();	
	static {
		//loadMusicGenresMap();
		
		//premieres, pop, raphip-hop, rock, alternative, country, latino, rbsoul, electronicdance,
		//reggae, comedyhumor, childrens-music, blues, jazz, classical, christian-gospel
		//soundtrack, world, spoken-word, holiday
		map.put("premieres", StandarMusicGenres.PREMIERES);
		map.put("pop", StandarMusicGenres.POP);
		map.put("raphip-hop", StandarMusicGenres.RAP);
		map.put("rock", StandarMusicGenres.ROCK);
		map.put("alternative", StandarMusicGenres.ALTERNATIVE);
		map.put("country", StandarMusicGenres.COUNTRY);
		map.put("latino", StandarMusicGenres.LATIN);
		map.put("rbsoul", StandarMusicGenres.R_AND_B);
		map.put("electronicdance", StandarMusicGenres.ELECTRONIC);
		map.put("reggae", StandarMusicGenres.REGGAE);
		map.put("comedyhumor", StandarMusicGenres.COMEDY);
		map.put("childrens-music", StandarMusicGenres.CHILDREN);
		map.put("blues", StandarMusicGenres.BLUES);
		map.put("jazz", StandarMusicGenres.JAZZ);
		map.put("classical", StandarMusicGenres.CLASSICAL);
		map.put("christian-gospel", StandarMusicGenres.CHRISTIAN_GOSPEL);
		map.put("soundtrack", StandarMusicGenres.SOUND_TRACK);
		map.put("world", StandarMusicGenres.WORLD);
		map.put("spoken-word", StandarMusicGenres.SPOKEN_WORD);
		map.put("holiday", StandarMusicGenres.HOLIDAY);
		
		//TODO
	}
	
	/*
	private static void loadMusicGenresMap(){
		List<GenreSite> genreSites = GenreSelectDao.selectGenreSites(SiteConstants.WEBSITE_VEVO, 
				Genre.CATE_MUSIC);
		for (GenreSite gs : genreSites) {
			siteStandarMap.put(gs.getSiteGenre(), gs.getStandarGenre());
		}
	}
	*/
	
	/**
	 * 修正单个genre
	 * @param mfGenre
	 * @return
	 */
	public static String remendGenre(String genreName){
		if(StringUtils.isNullOrEmpty(genreName)){
			return null;
		}
		
		//处理专有genre, 不存在则判断是标准genre
		String genre = map.get(genreName);
		return genre != null ? genre : genreName;
	}
	
	/**
	 * 处理全部genres(逗号分隔), 并防止重复
	 * @param genreNames
	 * @return
	 */
	public static String remendAllGenres(String genreNames){
		if(StringUtils.isNullOrEmpty(genreNames)){
			return null;
		}
		
		Set<String> genreSet = new HashSet<String>();
		
		String[] genres = genreNames.split("\\s*,\\s*");
		for (String g : genres) {
			String rg = remendGenre(g);
			if(rg != null){
				genreSet.add(rg);
			}		
		}
		
		return ArrayUtils.join(genreSet, ",");
	}
	
	/**
	 * vevo 内部使用的genres
	 * @return
	 */
	public static Set<String> getVevoInitGenres(){
		return map.keySet();
	}
}
